<!DOCTYPE HTML>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<style>
    .fixed-table-body {
        height: calc(73vh);
    }

    .fixed-table-footer {
        border-top: 0;
    }
</style>
<body class="gray-bg">
<div class="container-div">
    <div id="flexSearchBox" class="collapse out col-sm-12 search-box">
        <form id="user-form">
            <div class="select-list">
                <ul>
                    <li>
                        name：<input class="reset" type="text" name="name"/>
                    </li>
                    <li>
                        T Order：<input class="reset" type="text" name="tFileUrl"/>
                    </li>
                    <li>
                        sendWarehouseTask：<input class="reset" type="text" name="taskFileUrl"/>
                    </li>
                    <li>
                        state：<select name="status" th:with="type=${@dict.getType('erp_fbs_state')}">
                        <option value="">all</option>
                        <option th:each="e : ${type}" th:text="${e['dictLabel']}" th:value="${e['dictValue']}"></option>
                    </select>
                    </li>
                    <li class="time">
                        <label>warehousingTime:</label>
                        <input type="text" id="startTime" class="time-input reset" placeholder="start date"
                               name="beginIntoDate"/>
                        <span>to</span>
                        <input type="text" id="endTime" class="time-input reset" placeholder="end date" name="endIntoDate"/>
                    </li>
                    <li>
                        <a class="btn btn-success btn-rounded btn-sm" onclick="$.table.search()"><i
                                class="fa fa-search"></i>&nbsp;search</a>
                        <a class="btn btn-primary btn-rounded btn-sm reset-booton"><i
                                class="glyphicon glyphicon-repeat"></i>&nbsp;reset</a>
                    </li>
                </ul>
            </div>
        </form>
    </div>
    <div class="btn-group hidden-xs" id="toolbar" role="group">
        <a class="btn btn-outline btn-success btn-rounded" onclick="$.operate.add()"
           shiro:hasPermission="module:fbsHead:add">
            <i class="fa fa-plus"></i> add
        </a>
        <a class="btn btn-outline btn-danger btn-rounded" onclick="$.operate.batRemove()"
           shiro:hasPermission="module:fbsHead:remove">
            <i class="fa fa-trash-o"></i> delete
        </a>
        <a class="btn btn-outline btn-warning btn-rounded" onclick="beach('beach')"
           shiro:hasPermission="module:fbsHead:remove">
            <i class="glyphicon glyphicon-blackboard"></i> batchOutbound
        </a>
        <a class="btn btn-outline btn-info btn-rounded flex-botton" data-toggle="collapse" data-target="#flexSearchBox">
            <i class="glyphicon glyphicon-chevron-down">unfoldSearch
            </i>
        </a>
    </div>

    <div class="col-sm-12 select-info table-responsive">
        <table id="bootstrap-table" class="table text-nowrap table-hover" data-height="770"
               data-mobile-responsive="true"></table>
    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('module:fbsHead:edit')}]];
    var removeFlag = [[${@permission.hasPermi('module:fbsHead:remove')}]];
    var prefix = ctx + "module/fbsHead"
    var types = [[${@dict.getType('erp_fbs_state')}]];

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            edit_fbs_batchUrl: prefix + "/edit_fbs_batchUrl/{ids}/{names}",
            modalName: "转入FBS",
            showFooter: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '',
                    visible: false

                },
                {
                    title: 'serialNumber',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var pageSize = $('#bootstrap-table').bootstrapTable('getOptions').pageSize;     //通过table的#id 得到每页多少条
                        var pageNumber = $('#bootstrap-table').bootstrapTable('getOptions').pageNumber; //通过table的#id 得到当前第几页
                        return pageSize * (pageNumber - 1) + index + 1;    // 返回每条的序号： 每页条数 *（当前页 - 1 ）+ 序号
                    },
                    footerFormatter: function (value) {
                        return 'total';
                    }
                },
                {
                    title: 'operation',
                    clickToSelect : false,
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];

                        //未发货
                        if (row.status == 0) {
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="#" onclick="beach(\'' + "nobeach" + '\'' + ',\'' + row.id + '\'' + ',\'' + row.name + '\')"><i class="glyphicon glyphicon-blackboard"></i>EX-warehouse</a>');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="#" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>delete</a>');
                        }
                        //已审核
                        else if(row.status == 1){
                        }
                        //已出库
                        else if (row.status == 2){
                            //actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="#" onclick="beach(\'' + "nobeach" + '\'' + ',\'' + row.id + '\'' + ',\'' + row.name + '\')"><i class="glyphicon glyphicon-blackboard"></i>EX-warehouse</a>');
                        }

                        return actions.join('');
                    }
                },
                {
                    field: 'name',
                    align: 'center',
                    sortable: true,
                    title: '<span class="globalSearch_column">name</span>',
                },
                {
                    field: 'intoDate',
                    align: 'center',
                    sortable: true,
                    title: 'warehousingTime'
                },
                {
                    field: 'tFileUrl',
                    title: '<span class="globalSearch_column">T Order</span>',
                    sortable: true,
                    align: 'center',
                    formatter: function (value, row, index) {
                        return '<a target="view_window" href="/profile/fbs/' + value + '" >' + value + '</a>';
                    }
                },
                {
                    field: 'taskFileUrl',
                    title: '<span class="globalSearch_column">sendWarehouseTask</span>',
                    sortable: true,
                    align: 'center',
                    formatter: function (value, row, index) {
                        return '<a href="javascript:;" data-text="fbs/' + value + '" class="down">' + value + '</a>';
                    }
                },
                {
                    field: 'status',
                    title: 'state',
                    sortable: true,
                    align: 'center',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(types, value);
                    }
                },
                {
                    field: 'bz',
                    align: 'center',
                    sortable: true,
                    title: 'remark'
                },
                {
                    field: 'createBy',
                    align: 'center',
                    sortable: true,
                    title: 'createBy'
                },
                {
                    field: 'createDate',
                    align: 'center',
                    sortable: true,
                    title: 'createDate'
                },
                {
                    field: 'updateBy',
                    align: 'center',
                    sortable: true,
                    title: 'updateBy'
                },
                {
                    field: 'updateDate',
                    align: 'center',
                    sortable: true,
                    title: 'updateDate'
                },
                {
                    field: 'companyName',
                    align: 'center',
                    sortable: true,
                    title: 'company'
                }],
            onLoadSuccess: function (item, $element) {

                $('.fixed-table-footer').addClass("totalRowBackground-color");//合计行添加颜色
            },
        };
        $.table.init(options);
    });

    /*批量出库*/
    function beach (state, ids, names) {

        //批量操作
        if (state == "beach") {
            var rows = $.common.isEmpty($.table._option.id) ? $.table.selectFirstColumns() : $.table.selectColumns($.table._option.id);
            if (rows.length == 0) {
                $.modal.alertWarning("Please select at least one record");
                return;
            }
            var names = getBootstrapTableValueAsRow('name', rows);
            var url = $.table._option.edit_fbs_batchUrl.replace("{ids}", rows.join())
                .replace("{names}", names);
        }
        /*单个签收*/
        else {
            var url = $.table._option.edit_fbs_batchUrl.replace("{ids}", ids)
                .replace("{names}", names);
        }


        $.modal.open("批量出库" + $.table._option.modalName, url);
    }
</script>
</body>
</html>